package com.fs.sw.controller;

import com.fs.sw.pojo.Roles;
import com.fs.sw.pojo.Users;
import com.fs.sw.service.IUserService;
import com.fs.sw.utils.FunctionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(value = "用户接口")
@RestController
//@RequestMapping("")
public class UserController {
    @Autowired
    IUserService userService;

    @ApiOperation(value = "获取用户", notes = "根据id查询用户信息")
    @ApiImplicitParam(name = "id", value = "用户id", required=true, dataType = "String")
    @GetMapping("/user/{id}")
    public Users getUser(@PathVariable("id") Users users){

        return users;
    }

    @GetMapping("/role/{id}")
    public Roles getRole(@PathVariable("id") Roles roles){
//        roles.getUsers();
        return roles;
    }

    @GetMapping("/user/save")
    public void saveRole(@Valid @RequestBody Roles r, BindingResult error){
        FunctionUtil.shrowError(error);
        userService.addUser();
    }
}
